﻿@{
    ViewBag.Title = "公共部位";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

@using LeSoft.Application.Code;
<script>
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });

    var _pstructId = "";
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "==请选择组织机构==",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree();
                    $('#btn_Search').trigger("click");
                }
            }
        });
        $('#PStructTree').ComboBoxTreeSetValue(_organizeid);
    }

    //加载树
    function GetTree() {
        var item = {
            height: $(window).height() - 51.5,
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&type=4&OrganizeId=" + _organizeid,
            onnodeclick: function (item) {
                _pstructId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
   
    
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["PStructName"] = _pstructId;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["Type"] = "6";
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PublicArea/GetPageListJson",
            datatype: "json",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'PCode', hidden: true },
                { label: 'OrganizeId', name: 'OrganizeId', hidden: true },
                {
                    label: '审核标识', name: 'AuditFlag', hidden: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return rowObject.AuditMark;
                    }
                },
                { label: "公区名称", name: "Name", width: 200, align: "left", sortable: true },
                { label: "公区编号", name: "EnCode", width: 100, align: "left", sortable: true },
                { label: "房产全称", name: "PSAllName", width: 200, align: "left", sortable: true },
                 { label: "位置描述", name: "OtherCode", width: 200, align: "left", sortable: true },
                {
                    label: "标识方式", name: "FlagWay", width: 80, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "无标识";
                            case 1: return "rfid芯片";
                            case 2: return "条码";
                            case 3: return "二维码";
                            case 4: return "beacon";
                            default: return "";
                        }
                    }
                },
                { label: "标识编码", name: "FlagNo", width: 200, align: "left", sortable: true },
                {
                    label: "是否审核", name: "AuditMark", width: 80, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? " <i class='fa fa-check fa-2x' style='color:green;margin-left:10px;' ><i/>" : "";
                    }
                },
                { label: "审核人", name: "AuditMan", index: "AuditMan", width: 80, align: "left" },
                { label: "审核日期", name: "AuditDate", index: "AuditDate", width: 80, align: "left" },             
               
               // { label: "创建人", name: "CreateUserName", index: "CreateUserName", width: 80, align: "left" },
               // { label: "创建日期", name: "CreateDate", index: "CreateDate", width: 80, align: "left" },

               //{ label: "最终修改人", name: "ModifyUserName", index: "ModifyUserName", width: 80, align: "left" },
               // { label: "最终修改日期", name: "ModifyDate", index: "ModifyDate", width: 80, align: "left" },
                { label: "备注", name: "Memo", width: 200, align: "left", sortable: false }
            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'Code',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                Type:"6",
                keyword: $("#txt_Keyword").val(),
                PStructName: _pstructId,
                OrganizeId: _organizeid
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }, page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }


    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加巡检区域',
            url: '/ResourceManage/RS_PublicArea/Form?&type=add',
            width: "700px",
            height: "430px",
            //btn:Null
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("PCode");
        var AuditMark = $("#gridTable").jqGridRowValue("AuditFlag");
        if (checkedRow(keyValue)) {
            
            if (AuditMark == 0) {
                dialogOpen({
                    id: "Form",
                    title: '编辑巡检区域',
                    url: '/ResourceManage/RS_PublicArea/Form?keyValue=' + keyValue + "&type=edit",
                    width: "700px",
                    height: "430px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick();
                    }
                });
            }
            else {
                dialogOpen({
                    id: "Form",
                    title: '编辑巡检区域',
                    url: '/ResourceManage/RS_PublicArea/Form?keyValue=' + keyValue + "&type=edit",
                    width: "700px",
                    height: "430px",
                    btn: null,
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick();
                    }
                });
            }
        }
    }
    //删除
    function btn_delete(keyValue) {
        var keyValue = $("#gridTable").jqGridRowValue("PCode");
        if (checkedRow(keyValue)) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_PublicArea/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的业务！', 0);
        }
    }

    //关联巡检对象
    function btn_addItem() {
        var keyValue = $("#gridTable").jqGridRowValue("PCode");
        var OrganizeId = $("#gridTable").jqGridRowValue("OrganizeId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '关联巡检对象',
                url: '/ResourceManage/RS_PublicArea/RelationOIForm?ObjectId=' + keyValue + "&OrganizeId=" + OrganizeId,
                width: "700px",
                height: "430px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
        else {
            dialogMsg('请选择需要关联的对象！', 0);
        }
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree" style=" height: 320px; border-bottom: 1px dashed #cecece;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>                          
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入编码或名称查询" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>                     
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-authorize" class="btn btn-default" onclick="btn_addItem()"><i class="fa fa-gavel"></i>&nbsp;关联巡检对象</a>
                    </div>   
                    <script>$('.toolbar').authorizeButton()</script>               
                </div>
               
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
